/**
 * Title:        批量修改批示语
 * Company:      泛微软件
 */


package checktools;

import general.BaseBean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.bouncycastle.crypto.BufferedBlockCipher;
import org.bouncycastle.crypto.engines.AESFastEngine;
import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.params.ParametersWithIV;
import org.bouncycastle.util.encoders.Hex;
import org.json.JSONObject;

import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.workflow.request.WFLinkInfo;



public class SysphraseSet extends BaseBean implements checkToolsBase  {

    @Override
    public JSONObject checkData(HashMap dataMap) {
        setRecordSet();
        List resultList = new ArrayList();
        String result = "";

        String userids = Util.null2String(dataMap.get("userids"));
        if(userids.equals("")){
            result = resultERROR;
            resultList.add("请选择用户。");
            return formatReturnJsonCheck(result, resultList, this);
        }
        String phasecontent = Util.null2String(dataMap.get("phasecontent"));
        if(phasecontent.trim().equals("")){
            result = resultERROR;
            resultList.add("请输入批示语。");
            return formatReturnJsonCheck(result, resultList, this);
        }
        String[] useridArray = Util.TokenizerString2(userids, ",");
        String sqltemp = "";
        List<String> addedUserids = new ArrayList<String>();
        for(String userid : useridArray){
            if(Util.getIntValue(userid) > 0 && !addedUserids.contains(userid)){
                if(recordSet.getDBType().equals("oracle")){
                    sqltemp += "union select " + userid + ",'" + phasecontent + "','" + phasecontent + "' from dual ";
                }else{
                    sqltemp += "union select " + userid + ",'" + phasecontent + "','" + phasecontent + "' ";
                }
                addedUserids.add(userid);
            }
        }
        if(sqltemp.startsWith("union")){
            sqltemp = sqltemp.substring(5);
            String sqlInsert = "insert into sysphrase (hrmid,phraseshort,phrasedesc) " + sqltemp;
            recordSet.executeUpdate(sqlInsert);
            result = resultOk;
            resultList.add("数据插入成功，共插入" + addedUserids.size() + "条数据。");
        }else{
            result = resultERROR;
            resultList.add("数据插入失败");
        }
        
        return formatReturnJsonCheck(result, resultList, this);
    }

    @Override
    public JSONObject fixData(HashMap dataMap) {

        //重新加载DIV
        needReload = "1";
        return checkData(new HashMap());
    }

    @Override
    public String getClassName() {
        return "批量修改批示语";
    }

    @Override
    public String getClassDesc() {
        return "批量修改批示语";
    }

    @Override
    public String getPopupUrl() {
        return "/flowtoolbar/checkWithCondit/SysphraseSet.jsp";
    }

}



